package BehaviorDesignPattern.InterpreterPattern;

import BehaviorDesignPattern.InterpreterPattern.Interfase.Expression;

public class TestInterpreterPattern {
    public static void main(String[] args) {
        // 创建数字表达式
        Expression number1 = new NumberExpression(20);
        Expression number2 = new NumberExpression(5);
        Expression number3 = new NumberExpression(10);
        Expression number4 = new NumberExpression(4);
        Expression number5 = new NumberExpression(5);

        // 创建加法表达式: (20 + 5)
        Expression addExpression = new AddExpression(number1, number2);

        // 创建减法表达式: (20 + 5) - 10
        Expression subtractExpression = new SubtractExpression(addExpression, number3);

        // 创建乘法表达式: (20 + 5) - 10) * 4
        Expression multiplyExpression = new MultiplyExpression(subtractExpression, number4);

        // 创建除法表达式: ((20 + 5) - 10) * 4) / 5
        Expression divideExpression = new DivideExpression(multiplyExpression, number5);

        // 解释并计算结果
        int result = divideExpression.interpret();

        // 输出结果
        System.out.println("((20 + 5) - 10) * 4) / 5 " + result);
    }
}
